package com.xuchaotong.arr;

import java.util.ArrayList;
import java.util.List;

public class Array2D {

    public static ArrayList array2d(ArrayList list)
    {
        ArrayList retList=new ArrayList();
        int max=2<<(list.size()-1);
        for (int i=1;i<max;i++)
        {
            String[] dim=new String[list.size()];
            int temp=i;
            for(int j=list.size();j>0;j--) {
                if (temp >=Math.pow(2,j-1)) {
                    dim[list.size()-j] = String.valueOf(list.get(list.size()-j));
                    temp = temp-(int) Math.pow(2,j-1);
                }else
                {
                    dim[list.size()-j] ="-1";
                }
            }
            retList.add(dim);
        }
        return  retList;
    }
    public static void main(String args[])
    {
        ArrayList list=new ArrayList();
        list.add(2);
        list.add(6);
        list.add(7);
        List retList=array2d(list);
        for (int i=0;i<retList.size();i++)
        {
            String[] dim=(String[]) retList.get(i);
            for(int j=0;j<dim.length;j++)
            {
                System.out.print(dim[j]);
                System.out.print(" ");
            }
            System.out.println();
        }
    }
}
